/*
 * Copyright (c) 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.snj.visangedu.calendar;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.snj.visangedu.R;
import com.snj.visangedu.studytime.StudyPlannerFragment;

/**
 * @author AA@google.com (Your Name Here)
 *
 */

public class MyPlanAdapter extends PagerAdapter {

  private static final String TAG = "StudyPlan";

  private Context mContext;
  private LayoutInflater mLayoutInflater;

  private int NumberOfPages = 3;

  public MyPlanAdapter(Context context) {
    mContext = context;
    mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // layout.setOrientation(LinearLayout.VERTICAL);
  }

  @Override
  public int getCount() {
    return NumberOfPages;
  }

  @Override
  public boolean isViewFromObject(View view, Object object) {
    return view == ((LinearLayout) object);
  }

  public Object instantiateItem(ViewGroup container, int position) {
    Log.d(TAG, "instantiateItem, position = " + position);

    View itemView = null;
    if (position == 0) {
      if (StudyPlannerFragment.h1.vPage0 == null) {
        itemView = mLayoutInflater.inflate(R.layout.y_plan_page_0, container, false);
        StudyPlannerFragment.h1.vPage0 = itemView;
      }
      itemView = StudyPlannerFragment.h1.vPage0;

    } else if (position == 1) {
      if (StudyPlannerFragment.h1.vPage1 == null) {
        itemView = mLayoutInflater.inflate(R.layout.y_plan_page_1, container, false);
        StudyPlannerFragment.h1.vPage1 = itemView;
      }
      itemView = StudyPlannerFragment.h1.vPage1;

    } else if (position == 2) {
      if (StudyPlannerFragment.h1.vPage2 == null) {
        itemView = mLayoutInflater.inflate(R.layout.y_plan_page_2, container, false);
        StudyPlannerFragment.h1.vPage2 = itemView;

        container.addView(itemView);
        StudyPlannerFragment.h1.Init_Async();

        return itemView;
      }
      itemView = StudyPlannerFragment.h1.vPage2;
    }

    container.addView(itemView);

    return itemView;
  }


  public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((LinearLayout) object);
  }

@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
	// TODO Auto-generated method stub
	
}

@Override
public void finishUpdate(View arg0) {
	// TODO Auto-generated method stub
	
}

@Override
public Object instantiateItem(View arg0, int arg1) {
	// TODO Auto-generated method stub
	return null;
} 

@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
	// TODO Auto-generated method stub
	
}

@Override
public Parcelable saveState() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void startUpdate(View arg0) {
	// TODO Auto-generated method stub
	
}

}
